const Service = require('egg').Service
class ImgInsetService extends Service {
    async updateImg (userInfoFromWe) {
        const { ctx, app } = this
        console.log('---userInfoFromWe----',userInfoFromWe);
        
        try {
            const userInfo = await app.mysql.get('img_list', {openid:userInfoFromWe.openid});
            if(userInfo) {
                // 找到了就更新 图片地址
                return userInfo
            }else{
                // 没有找到就插入
                const result = await app.mysql.insert('img_list', {
                    openid:userInfoFromWe.openid,
                    session_key:userInfoFromWe.session_key
                });
                console.log('-------',userInfo,result);
                return result
            };
        } catch (err) {
            console.log(err);
            return null
        }  
    }

    async login () {
        const { ctx, app } = this
        // const sql = 
    }
}
module.exports = ImgInsetService

